#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int MAXN = 1<<17;
const int MAXX = 1e5+10;

int k,all,f[MAXN],n,c[MAXN],v[MAXX],lg[MAXN];
ll s[MAXX],sc[MAXN];

int jump(int x,ll t){
	ll val = s[x] + t;
	if(val >= s[n]) return n;
	return upper_bound(s+1,s+n+1,val) - s - 1;
}

int main (){
	k = in; n = in; all = 1<<k; for(int i = 0;i < k;i++) c[i] = in;for(int i = 2;i < all;i<<=1) lg[i] = lg[i>>1] + 1;
	for(int i = 1;i <= n;i++) v[i] = in,s[i] = s[i-1]+v[i];
	for(int i = 1;i < all;i++) sc[i] = c[lg[i&-i]] + sc[i ^ (i & -i)];
	for(int i = 1;i < all;i++)
		for(int j = 0;j < k;j++)
			if(i & (1<<j))
				f[i] = max(f[i],jump(f[i^(1<<j)],c[j]));
	ll ans = -1;
	for(int i = all - 1;i >= 0;i--) if(f[i] == n) ans = max(ans,sc[(all-1)^i]);
	printf("%lld\n",ans);
	return 0;
}

